/**
 * Copyright (C), 2019-2020, 宇信融汇
 * FileName: DAO
 * Author:   666
 * Date:     2020/8/18 22:41
 * Description: 泛型联系
 * History:
 * <author>          <time>          <version>          <desc>
 * 666           修改时间           版本号              描述
 */
package c_010.generic.test;

import java.util.*;

/**
 * @Classname DAO
 * @Description TODO
 * @Date 2020/8/18 22:41
 * @Created by 666
 */
public class DAO<T> {
    private Map<String, T> map = new HashMap<>();

    public void save(String id, T t) {
        map.put(id, t);
    }

    public void delete(String id, T t) {
        map.remove(id, t);
    }

    public void update(String id, T t) {
        if (map.containsKey(id)) {
            map.put(id, t);
        }
    }

    public T get(String id) {
        return map.get(id);
    }

    public List<T> list() {
//        Collection<T> collection = map.values();
//        return (List<T>) collection;
        ArrayList<T> list = new ArrayList<>();
        Collection<T> collection = map.values();
        for (T t : collection) {
            list.add(t);
        }
        return list;
    }
}

